package com.foreverwin.mes.integration.config;

import com.foreverwin.mes.integration.handler.MessageLogHandler;
import com.foreverwin.mes.integration.soap.material.service.MaterialReplicateService;
import com.foreverwin.mes.integration.soap.materialissue.service.MaterialIssueService;
import com.foreverwin.mes.integration.soap.plannedorder.service.PlannedOrderReplicateService;
import org.apache.cxf.Bus;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * @author Ervin Chen
 * @date 2020/1/9 10:10
 */
@Configuration
public class IntegrationConfiguration {

    @Autowired
    Bus bus;

    @Autowired
    MaterialReplicateService materialReplicateService;

    @Autowired
    PlannedOrderReplicateService plannedOrderReplicateService;

    @Autowired
    MaterialIssueService materialIssueService;

    @Bean
    public Endpoint materialReplicateWebService() {
        EndpointImpl endpoint = new EndpointImpl( bus, materialReplicateService );
        endpoint.getHandlers().add( new MessageLogHandler() );
        //显示要发布的名称
        endpoint.publish("/materialReplicateService");
        return endpoint;
    }

    @Bean
    public Endpoint plannedOrderReplicateWebService() {
        EndpointImpl endpoint = new EndpointImpl( bus, plannedOrderReplicateService );
        endpoint.getHandlers().add( new MessageLogHandler() );
        //显示要发布的名称
        endpoint.publish("/plannedOrderReplicateService");
        return endpoint;
    }

    @Bean
    public Endpoint materialIssueWebService() {
        EndpointImpl endpoint = new EndpointImpl( bus, materialIssueService );
        endpoint.getHandlers().add( new MessageLogHandler() );
        //显示要发布的名称
        endpoint.publish("/materialIssueService");
        return endpoint;
    }

}
